package com.itema.controller;

import com.itema.pojo.PageResult;
import com.itema.pojo.Result;
import com.itema.pojo.Student;
import com.itema.pojo.StudentQueryParam;
import com.itema.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
@Slf4j
public class StudentController {
    @Autowired
    StudentService studentService;

    /**
     * 条件分页查询
     */
    @GetMapping
    public Result page(StudentQueryParam studentQueryParam){

        PageResult pageResult = studentService.page(studentQueryParam);
        return Result.success(pageResult);
    }

    /**
     * 新增学员
     */
    @PostMapping
    public Result add(@RequestBody Student student) {
        log.info("新增员工，员工数据： {}", student);
        studentService.add(student);
        return Result.success();
    }
    /**
     * 根据ID查询
     */
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id){
        log.info("根据Id查询:{}", id);
        Student student=studentService.findById(id);
        return Result.success(student);
    }

    /**
     * 修改
     */
    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("修改员工信息: {}", student);
        studentService.update(student);
        return Result.success();
}
    /**
     * 批量删除学生
     */
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        log.info("批量删除学生: {}", ids);
        studentService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 违纪处理
     */
    @PutMapping("violation/{id}/{score}")
    public Result violation(@PathVariable Integer id, @PathVariable Integer score){
        log.info("违纪处理: {}", id);
        studentService.violation(id, score);
        return Result.success();
    }


}
